package com.future.orm.mapping;

import com.future.orm.util.GenericTokenParser;
import com.future.orm.util.ParameterMappingTokenHandler;
import lombok.Data;
import lombok.ToString;

/**
 * @author shiyong
 * 2020/5/16 17:32
 */
@Data
@ToString
public class MappedStatement {

    /**
     * 唯一标识
     */
    private String id;

    /**
     * sql语句
     */
    private String sql;

    /**
     * 参数值类型
     */
    private Class<?> parameterType;

    /**
     * 返回值类型
     */
    private Class<?> resultType;

    /**
     * SQL语句类型
     */
    private SqlCommandType sqlCommandType;

    /**
     * 解析sql，返回BoundSql
     *
     * @return com.study.orm.mapping.BoundSql
     * @author shiyong
     * 2020/5/27 11:44
    */
    public BoundSql getBoundSql() {
        ParameterMappingTokenHandler handler = new ParameterMappingTokenHandler();
        GenericTokenParser parser = new GenericTokenParser("#{", "}", handler);

        return new BoundSql(parser.parse(this.sql), handler.getParameterMappingList());
    }

}
